﻿using System;
using Magellan.Utilities;

namespace Magellan.Routing
{
    public class LiteralSegment : Segment
    {
        private readonly string _literal;

        public LiteralSegment(string literal)
        {
            Guard.ArgumentNotNullOrEmpty(literal, "literal");
            _literal = literal;
        }

        public override SegmentPathMatch MatchPath(IRoute route, PathIterator reader)
        {
            var next = reader.Next();
            return String.Equals(next, _literal, StringComparison.InvariantCultureIgnoreCase)
                ? SegmentPathMatch.Successful()
                : SegmentPathMatch.Failure(string.Format("Expected segment '{0}'; got '{1}'", _literal, next));
        }

        public override SegmentValueMatch MatchValues(IRoute route, RouteValueBag values)
        {
            return SegmentValueMatch.Successful(_literal);
        }
    }
}
